package com.chainyoung.component_tmperson.ui.activity.account;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chainyoung.common.appcommon.entity.RecieveAccount;
import com.chainyoung.common.base.BaseActivity;
import com.chainyoung.common.constant.LibConstant;
import com.chainyoung.common.di.AppComponent;
import com.chainyoung.common.utils.SPUtil;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.di.component.DaggerPersonActivityComponent;
import com.chainyoung.component_tmperson.di.module.PersonActivityModule;
import com.chainyoung.component_tmperson.ui.activity.account.BindBankCardActivity;
import com.chainyoung.component_tmperson.ui.mvp.contract.AccountInfoContract;
import com.chainyoung.component_tmperson.ui.mvp.presenter.AccountInfoPresenter;

import java.util.TreeMap;

import butterknife.BindView;


public class MyBankCardActivity extends BaseActivity<AccountInfoPresenter> implements AccountInfoContract.View {


    @BindView(R2.id.tv_bank_name)
    TextView tvBankName;
    @BindView(R2.id.tv_bank_card_no)
    TextView tvBankCardNo;
    @BindView(R2.id.tv_owner_name)
    TextView tvOwnerName;
    @BindView(R2.id.tv_bank_branch_name)
    TextView tvBankBranchName;

    private RecieveAccount account;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPersonActivityComponent.builder()
                .appComponent(appComponent)
                .personActivityModule(new PersonActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initUI() {
        setCurrentTitle(R.string.tmtrade_bank);
        showAndSetBarRightText(R.string.tmperson_update);
    }

    @Override
    protected void initData() {

    }


    @Override
    protected void onResume() {
        super.onResume();
        TreeMap<String, Object> map = new TreeMap<>();
        map.put("token", SPUtil.getString(LibConstant.TOKEN));
        map.put("type", 1);
        mPresenter.getRecieveAccountInfo(map);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.tmperson_my_bank_card;
    }


    @Override
    public void onRightTxtClicked(View v) {
        super.onRightTxtClicked(v);
        Intent intent=new Intent(mContext,BindBankCardActivity.class);
        intent.putExtra("isEdit",true);
        intent.putExtra("accountItem",account);
        mContext.startActivity(intent);

    }

    @Override
    public void onGetAccountInfo(RecieveAccount data) {
        account=data;
        tvBankName.setText(data.getBank());
        String str=data.getBankcard().substring(0,data.getBankcard().length()-4);
        tvBankCardNo.setText(data.getBankcard().replace(str,"**** **** ****"));
        tvBankBranchName.setText(data.getBankaddr());
        tvOwnerName.setText(data.getName());
    }


}
